import React, { useState, useEffect } from 'react'
import './Chat.scss'
import { useNavigate } from 'react-router-dom'
import { getUserInfo } from '../../../../utils/request'

export default function Chat({ obj, convId }) {
    let navigate = useNavigate()
    const [user, setUser] = useState({})
    let userId = localStorage.getItem('userId')
    useEffect(() => {
        const friedId = obj.members.find((m) => m !== userId)
        getUserInfo(friedId).then((res) => {
            setUser(res.data);
        })
    }, [obj, userId])



    return (
        <div className='chat' onClick={() => { navigate('/chatmes', { state: { user, convId, obj } }) }}>
            <img className='message_img' src={user.img ? user.img : '/张杰.jpg'} alt="" />
            <div className='chat_content'>
                <div className='chat_content_top'>{user && user.userName}</div>
                <div className='chat_content_bottom'>你好，我是一个聊天机器人</div>
            </div>
            <div className='chat_content_right'>
                <div className='chat_content_right'>
                    time
                </div>
                <div>
                    消息
                </div>
            </div>
        </div>
    )
}
